
import { ActionReducerMap, MetaReducer } from '@ngrx/store';
import { environment as env } from '@env/environment';
import { LoadState } from './interceptors/load.models';
import { AuthState } from './auth/auth.models';
import { initStateFromLocalStorage } from './meta-reducers/init-state-from-local-storage.reducer';
import { debug } from './meta-reducers/debug.reducer';
import { loadReducer } from './interceptors/load.reducer';
import { authReducer } from './auth/auth.reducer';

/**
 * 应用根状态接口
 */
export interface AppState {
  load: LoadState; // 加载状态
  auth: AuthState; // 认证状态
}

export const reducers: ActionReducerMap<AppState> = {
  load: loadReducer,
  auth: authReducer
};

/**
 * Meta Reducers 配置
 * 按执行顺序排列：后添加的先执行
 */
export const metaReducers: MetaReducer<AppState>[] = [
  initStateFromLocalStorage
];

// 开发环境添加额外的 Meta Reducers
if (!env.production) {
  metaReducers.unshift(debug);
}